﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EBA.MQ
{
    /// <summary>
    /// 更新路由表
    /// </summary>
    public class UpdateRouteList
    {
        private string FilePath
        {
            get;
            set;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="path"></param>
        public UpdateRouteList(string path)
        {
            FilePath = path;
        }

        private void Update(RouteListPayLoad routelists)
        {
            //var config = AppRuntime.OpenConfiguration(FilePath);
            //if (config != null)
            //{
            //    var eabSectionGroup = config.GetSectionGroup("eba");
            //    var sections = eabSectionGroup.Sections.Get("mq") as MessageQueueConfigurationSection;
            //    foreach (var route in routelists.Routes)
            //    {
            //        var function = sections.Routes.Get(route.Key);
            //        if (function != null)
            //        {
            //            var bindings = (function as RouteConfigurationElement).Bindings;
            //            foreach (var address in route.Value)
            //            {
            //                var binding = bindings.Get(address);
            //                if (binding == null)
            //                {
            //                    binding = new BindingConfigurationElement();
            //                    binding.Binding = address;
            //                    bindings.Add(new BindingConfigurationElement());
            //                }
            //            }
            //        }
            //        else
            //        {
            //            var bindings = new  BindingsConfigurationElementCollection();
            //            foreach (var address in route.Value)
            //            {
            //                var binding = new BindingConfigurationElement();
            //                binding.Binding = address;
            //                bindings.Add(binding);
            //            }
            //        }
            //    }
            //}
            //config.Save();
        }
    }
}
